//
//  LTTabBar.m
//  XHLKit
//
//  Created by qinyulun on 16/6/18.
//  Copyright © 2016年 leTian. All rights reserved.
//

#import "LTTabBar.h"
#import "XHLMacroDefin.h"
#import "UIView+XHLKit.h"

@implementation LTTabBar

- (nonnull instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        UIButton *publishButton = [[UIButton alloc] init];
        [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateHighlighted];
        [self addSubview:publishButton];
        publishButton.lt_centerX = SCREEN_WIDTH/2-[[publishButton backgroundImageForState:UIControlStateNormal] size].width/2;
        publishButton.lt_centerY = self.lt_centerY;
        CGRect newFrame = publishButton.frame;
        newFrame.size = [[publishButton backgroundImageForState:UIControlStateNormal] size];
        publishButton.frame = newFrame;
        [publishButton addTarget:self action:@selector(publishClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}

- (void)publishClick
{
    LTLog(@"publishClick");
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    // 原来的4个
    CGFloat width = self.lt_width / 5;
    int index = 0;
    for (UIControl *control in self.subviews) {
        if (![control isKindOfClass:[UIControl class]] || [control isKindOfClass:[UIButton class]]) continue;
        control.lt_width = width;
        control.lt_x = index > 1 ? width * (index + 1) : width * index;
        index++;
    }
}

@end
